package com.ruoyi.mes.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.mes.vo.wksp.StartVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.mes.domain.WkspTask;
import com.ruoyi.mes.service.IWkspTaskService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 车间任务Controller
 *
 * @author LongAndHao
 * @date 2023-04-04
 */
@Api(tags = "车间任务")
@RestController
@RequestMapping("/mes/task")
public class WkspTaskController extends BaseController {
    @Autowired
    private IWkspTaskService wkspTaskService;

    /**
     * 查询车间任务列表
     */
    @ApiOperation(value = "查询车间任务列表")
  //  @PreAuthorize("@ss.hasPermi('mes:task:list')")
    @GetMapping("/list")
    public TableDataInfo list(WkspTask wkspTask) {
        startPage();
        List<WkspTask> list = wkspTaskService.selectWkspTaskList(wkspTask);
        return getDataTable(list);
    }

    /**
     * 导出车间任务列表
     */
    @ApiOperation(value = "导出车间任务列表")
   // @PreAuthorize("@ss.hasPermi('mes:task:export')")
    @Log(title = "车间任务", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WkspTask wkspTask) {
        List<WkspTask> list = wkspTaskService.selectWkspTaskList(wkspTask);
        ExcelUtil<WkspTask> util = new ExcelUtil<WkspTask>(WkspTask.class);
        util.exportExcel(response, list, "车间任务数据");
    }

    /**
     * 获取车间任务详细信息
     */
    @ApiOperation(value = "获取车间任务详细信息")
  //  @PreAuthorize("@ss.hasPermi('mes:task:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(wkspTaskService.selectWkspTaskById(id));
    }

    /**
     * 新增车间任务
     */
    @ApiOperation(value = "新增车间任务")
   // @PreAuthorize("@ss.hasPermi('mes:task:add')")
    @Log(title = "车间任务", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WkspTask wkspTask) {
        return toAjax(wkspTaskService.insertWkspTask(wkspTask));
    }

    /**
     * 修改车间任务
     */
    @ApiOperation(value = "修改车间任务")
  //  @PreAuthorize("@ss.hasPermi('mes:task:edit')")
    @Log(title = "车间任务", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WkspTask wkspTask) {
        return toAjax(wkspTaskService.updateWkspTask(wkspTask));
    }

    /**
     * 删除车间任务
     */
    @ApiOperation(value = "删除车间任务")
   // @PreAuthorize("@ss.hasPermi('mes:task:remove')")
    @Log(title = "车间任务", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(wkspTaskService.deleteWkspTaskByIds(ids));
    }

    //*************************

    /**
     * 领料清单
     * @param id 车间任务id
     * @return
     */
    @GetMapping("/pickingList")
    public AjaxResult pickingList(@RequestParam Long id){
        return wkspTaskService.pickingList(id);
    }

    /**
     * 确认领料
     * @param id 车间任务id
     * @return
     */
    @PostMapping("/confirmPicking")
    public AjaxResult confirmPicking(@RequestParam Long id){
        return wkspTaskService.confirmPicking(id);
    }

    /**
     * 生成任务卡
     * @param startVo
     * @return
     */
    @PostMapping("/start")
    public AjaxResult start(@RequestBody StartVo startVo){
        return wkspTaskService.start(startVo);
    }

    /**
     * 生成任务卡
     * @param startVo
     * @return
     */
    @PostMapping("/start1")
    public AjaxResult start1(@RequestBody StartVo startVo){
        return wkspTaskService.start1(startVo);
    }
    /**
     * 撤回车间任务卡
     * @param id 车间任务id
     * @return
     */
    @PostMapping("/revokeTaskCart")
    public AjaxResult revokeTaskCart(@RequestParam Long id){
        return wkspTaskService.revokeTaskCart(id);
    }


    /**
     * 删 - 车间任务 (是否已领料)
     * @param id 车间任务id
     * @return
     */
    @DeleteMapping("/deleteWskpTask")
    public AjaxResult deleteWskpTask(@RequestParam Long id){
        return wkspTaskService.deleteWskpTask(id);
    }


    /**
     * 完工入库 (车间任务已完工)
     * @param id 车间任务id
     * @return
     */
    @PostMapping("/finishInhou")
    public AjaxResult finishInhou(@RequestParam Long id){
        return wkspTaskService.finishInhou(id);
    }


    @GetMapping("/jianting")
    public AjaxResult jianting(@RequestParam Long id){
        return wkspTaskService.jianting(id);
    }
 //质量分析
    @PostMapping("/pass")
    public AjaxResult pass(@RequestParam Long id){
        return wkspTaskService.pass(id);
    }
}
